# -*- coding: utf-8 -*-
#
# Author:: hanjunfeng
# Date:: 2022/7/7
import datetime
import os

from submodules.common.lib import local_paths
from submodules.common.lib.datetime_ import get_timestamp_human

from lib import ths_
from lib.character import (
    get_golden_cross_combo,
    get_ma_up_combo,
    get_golden_cross_socre,
)
from lib.common import trans_ths_txt_to_list
from lib.indicator import get_ma_list, get_boll_list

from lib.send_email import send_email_remind
from lib.ths_ import get_candles_data
from workspace.get_etf_list import get_etf_list


def main():
    email_info_list = []
    email_info_list2 = []

    condition_list = set()
    condition_list2 = set()

    project_path = local_paths.project_path
    txt_path = os.path.join(project_path, "data", "ETF", "Table.txt")
    fund_list = trans_ths_txt_to_list(txt_path)

    etf_list = get_etf_list()
    # 测试
    # for item in fund_list[:20]:
    for item in etf_list:
        name = item["tag"]
        code = item["fundCode"]
        if code[:1] == "1":
            ths_code = "sz_" + code
        if code[:1] == "5":
            ths_code = "sh_" + code
        candles_data = get_candles_data(ths_code)
        if len(candles_data) < 30:
            continue
        ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
        ma_list_type10 = get_ma_list(candles_data, ma_type=10, offset=0)
        ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
        ma_list_type20 = get_ma_list(candles_data, ma_type=20, offset=0)
        ma_list_type30 = get_ma_list(candles_data, ma_type=30, offset=0)
        boll_list_type15 = get_boll_list(candles_data, mid=15, offset=0)
        golden_cross_combo_3and30 = get_golden_cross_combo(
            ma_list_type3, ma_list_type30
        )
        golden_cross_combo_3and20 = get_golden_cross_combo(
            ma_list_type3, ma_list_type20
        )

        current_price = candles_data[0][4]
        high_price = candles_data[0][2]
        low_price = candles_data[0][3]
        low_price_offset1 = candles_data[1][3]
        low_price_offset2 = candles_data[2][3]

        gains_percent = round(candles_data[0][7], 1)
        ma_up_combo = get_ma_up_combo(ma_list_type3)
        ma_up_combo_type15 = get_ma_up_combo(ma_list_type15)
        ma_up_combo_type30 = get_ma_up_combo(ma_list_type30)

        interval_lenght = 15
        golden_cross_socre = get_golden_cross_socre(
            ma_list_type3, ma_list_type15, length=interval_lenght
        )

        # 上涨中
        if golden_cross_combo_3and30 >= 3:
            email_info_list.append(
                [
                    name,
                    ths_code,
                    golden_cross_socre,
                    ma_up_combo,
                    golden_cross_combo_3and30,
                    current_price,
                    gains_percent,
                ]
            )

        # 买入点
        if golden_cross_combo_3and20 >= 1 and (
                (ma_up_combo <= 0 and low_price <= ma_list_type10[0]) or ma_up_combo == 1):
            email_info_list2.append(
                [
                    name,
                    ths_code,
                    golden_cross_socre,
                    ma_up_combo,
                    golden_cross_combo_3and20,
                    current_price,
                    gains_percent,
                ]
            )

    email_info_list = sorted(email_info_list, key=lambda x: x[4], reverse=True)
    email_info_list2 = sorted(email_info_list2, key=lambda x: x[2], reverse=True)

    print(len(email_info_list))
    print(len(email_info_list2))
    print(email_info_list)
    print(email_info_list2)
    """
    # https://www.futunn.com/stock/06881-HK/
    https://pqa9p2.smartapps.baidu.com/pages/view/view?code=688317

    名称
    Code
    GxSc
    MaC
    GxC
    价格
    涨幅
    """

    # 大盘信息
    up_str_emoji = "🔴"
    down_str_emoji = "🟢"
    up_str = "O"
    down_str = "X"

    # 上证
    ths_code1 = "hs_1A0001"
    candles_data = ths_.get_candles_data(ths_code1)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji1 = up_str_emoji
    else:
        emoji1 = down_str_emoji

    if golden_cross_combo > 0:
        emoji1x = up_str_emoji
    else:
        emoji1x = down_str_emoji
    # 深成
    ths_code2 = "sz_399001"
    candles_data = ths_.get_candles_data(ths_code2)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji2 = up_str_emoji
    else:
        emoji2 = down_str_emoji

    if golden_cross_combo > 0:
        emoji2x = up_str_emoji
    else:
        emoji2x = down_str_emoji
    # 创业
    ths_code3 = "sz_399006"
    candles_data = ths_.get_candles_data(ths_code3)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji3 = up_str_emoji
    else:
        emoji3 = down_str_emoji

    if golden_cross_combo > 0:
        emoji3x = up_str_emoji
    else:
        emoji3x = down_str_emoji
    # 恒生
    ths_code4 = "176_HSI"
    candles_data = ths_.get_candles_data(ths_code4)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji4 = up_str_emoji
    else:
        emoji4 = down_str_emoji

    if golden_cross_combo > 0:
        emoji4x = up_str_emoji
    else:
        emoji4x = down_str_emoji
    # 恒科
    ths_code5 = "176_HS2083"
    candles_data = ths_.get_candles_data(ths_code5)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji5 = up_str_emoji
    else:
        emoji5 = down_str_emoji

    if golden_cross_combo > 0:
        emoji5x = up_str_emoji
    else:
        emoji5x = down_str_emoji
    # 国企
    ths_code6 = "176_HSCEI"
    candles_data = ths_.get_candles_data(ths_code6)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji6 = up_str_emoji
    else:
        emoji6 = down_str_emoji

    if golden_cross_combo > 0:
        emoji6x = up_str_emoji
    else:
        emoji6x = down_str_emoji
    # 纳指
    ths_code7 = "88_IXIC"
    candles_data = ths_.get_candles_data(ths_code7)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji7 = up_str_emoji
    else:
        emoji7 = down_str_emoji

    if golden_cross_combo > 0:
        emoji7x = up_str_emoji
    else:
        emoji7x = down_str_emoji
    # 标普
    ths_code8 = "88_SPX"
    candles_data = ths_.get_candles_data(ths_code8)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji8 = up_str_emoji
    else:
        emoji8 = down_str_emoji

    if golden_cross_combo > 0:
        emoji8x = up_str_emoji
    else:
        emoji8x = down_str_emoji
    # 道琼斯
    ths_code9 = "88_DJI"
    candles_data = ths_.get_candles_data(ths_code9)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji9 = up_str_emoji
    else:
        emoji9 = down_str_emoji

    if golden_cross_combo > 0:
        emoji9x = up_str_emoji
    else:
        emoji9x = down_str_emoji
    # 德国
    ths_code10 = "88_GDAXI"
    candles_data = ths_.get_candles_data(ths_code10)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji10 = up_str_emoji
    else:
        emoji10 = down_str_emoji

    if golden_cross_combo > 0:
        emoji10x = up_str_emoji
    else:
        emoji10x = down_str_emoji
    # 英国
    ths_code11 = "88_FTSE"
    candles_data = ths_.get_candles_data(ths_code11)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji11 = up_str_emoji
    else:
        emoji11 = down_str_emoji

    if golden_cross_combo > 0:
        emoji11x = up_str_emoji
    else:
        emoji11x = down_str_emoji
    # 法国
    ths_code12 = "88_FCHI"
    candles_data = ths_.get_candles_data(ths_code12)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji12 = up_str_emoji
    else:
        emoji12 = down_str_emoji

    if golden_cross_combo > 0:
        emoji12x = up_str_emoji
    else:
        emoji12x = down_str_emoji
    # 日经
    ths_code13 = "88_N225"
    candles_data = ths_.get_candles_data(ths_code13)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji13 = up_str_emoji
    else:
        emoji13 = down_str_emoji

    if golden_cross_combo > 0:
        emoji13x = up_str_emoji
    else:
        emoji13x = down_str_emoji
    # 多伦多
    ths_code14 = "88_GSPTSE"
    candles_data = ths_.get_candles_data(ths_code14)
    ma_list_type3 = get_ma_list(candles_data, ma_type=3, offset=0)
    ma_list_type15 = get_ma_list(candles_data, ma_type=15, offset=0)
    ma_up_combo = get_ma_up_combo(ma_list_type3)
    golden_cross_combo = get_golden_cross_combo(ma_list_type3, ma_list_type15)
    if ma_up_combo > 0:
        emoji14 = up_str_emoji
    else:
        emoji14 = down_str_emoji

    if golden_cross_combo > 0:
        emoji14x = up_str_emoji
    else:
        emoji14x = down_str_emoji

    URL = "https://m.10jqka.com.cn/stockpage/"
    text_content = ""  # 初始化 text_content

    text_content += '<div style="text-align:center">'
    text_content += f"<a href='{URL}{ths_code1}'>上证</a>"
    text_content += f"：{emoji1}" + "&nbsp;" * 2 + f"{emoji1x}"
    text_content += "　" * 1
    text_content += f"<a href='{URL}{ths_code2}'>深成</a>"
    text_content += f"：{emoji2}" + "&nbsp;" * 2 + f"{emoji2x}"
    text_content += "　" * 1
    text_content += f"<a href='{URL}{ths_code3}'>创业</a>"
    text_content += f"：{emoji3}" + "&nbsp;" * 2 + f"{emoji3x}"
    text_content += "</div>"
    text_content += "<br/>"

    text_content += '<div style="text-align:center">'
    text_content += f"<a href='{URL}{ths_code4}'>恒生</a>"
    text_content += f"：{emoji4}" + "&nbsp;" * 2 + f"{emoji4x}"
    text_content += "　" * 1
    text_content += f"<a href='{URL}{ths_code5}'>恒科</a>"
    text_content += f"：{emoji5}" + "&nbsp;" * 2 + f"{emoji5x}"
    text_content += "　" * 1
    text_content += f"<a href='{URL}{ths_code6}'>国企</a>"
    text_content += f"：{emoji6}" + "&nbsp;" * 2 + f"{emoji6x}"
    text_content += "</div>"
    text_content += "<br/>"

    text_content += '<div style="text-align:center">'
    text_content += f"<a href='{URL}{ths_code7}'>纳指</a>"
    text_content += f"：{emoji7}" + "&nbsp;" * 2 + f"{emoji7x}"
    text_content += "　" * 1
    text_content += f"<a href='{URL}{ths_code8}'>标普</a>"
    text_content += f"：{emoji8}" + "&nbsp;" * 2 + f"{emoji8x}"
    text_content += "　" * 1
    text_content += f"<a href='{URL}{ths_code9}'>道指</a>"
    text_content += f"：{emoji9}" + "&nbsp;" * 2 + f"{emoji9x}"
    text_content += "</div>"
    text_content += "<br/>"

    text_content += '<div style="text-align:center">'
    text_content += f"<a href='{URL}{ths_code10}'>德国</a>"
    text_content += f"：{emoji10}" + "&nbsp;" * 2 + f"{emoji10x}"
    text_content += "　" * 1
    text_content += f"<a href='{URL}{ths_code11}'>英国</a>"
    text_content += f"：{emoji11}" + "&nbsp;" * 2 + f"{emoji11x}"
    text_content += "　" * 1
    text_content += f"<a href='{URL}{ths_code12}'>法国</a>"
    text_content += f"：{emoji12}" + "&nbsp;" * 2 + f"{emoji12x}"
    text_content += "</div>"
    text_content += "<br/>"

    ## 数据表格1
    # text_content += '<div style="text-align:center">'
    # text_content += f"<a href='{URL}{ths_code13}'>日经</a>"
    # text_content += f"：{emoji13}" + "&nbsp;" * 2 + f"{emoji1313}"
    # text_content += "　" * 1
    # text_content += f"<a href='{URL}{ths_code14}'>多伦多</a>"
    # text_content += f"：{emoji14}" + "&nbsp;" * 2 + f"{emoji1414}"
    # text_content += "</div>"
    # text_content += "<br/>"

    # table_head_common = f'''
    # <table border="0" align="center"><tr><td align="center" bgcolor="#AFD7F5" width="300">&nbsp;&nbsp;&nbsp;名称&nbsp;&nbsp;&nbsp;</td><td align="center" bgcolor="#AFD7F5" width="80">Code</td><td align="center" bgcolor="#AFD7F5" width="80">GxSc</td><td align="center" bgcolor="#AFD7F5" width="80">MaC</td><td align="center" bgcolor="#AFD7F5" width="80">GxC</td><td align="center" bgcolor="#AFD7F5" width="80">价格</td><td align="center" bgcolor="#AFD7F5" width="100">涨幅</td></tr>
    # '''
    table_head_common = f"""
    <table border="0" align="center"><tr><td align="center" bgcolor="#AFD7F5" width="280">&nbsp;&nbsp;&nbsp;名称&nbsp;&nbsp;&nbsp;</td><td align="center" bgcolor="#AFD7F5" width="80">Code</td><td align="center" bgcolor="#AFD7F5" width="80">MaCo</td><td align="center" bgcolor="#AFD7F5" width="80">GxCo↓</td><td align="center" bgcolor="#AFD7F5" width="80">价格</td><td align="center" bgcolor="#AFD7F5" width="100">涨幅</td></tr>
    """
    data = email_info_list
    title = "上涨中排行"
    if data.__len__() > 0:
        if len(title) > 0:
            text_content += f"""<div align=center><b>{title}</b></div>"""
        text_content += """<div align=center>"""
        text_content += table_head_common
        for item in data:
            name = item[0]
            name = name.replace("ETF", "")
            if len(name) > 4:
                name = name[:4] + "."
            ths_code = item[1]
            code = ths_code[3:]
            golden_cross_socre = item[2]
            ma_up_combo = item[3]
            golden_cross_combo = item[4]
            price = round(item[5], 2)
            gains_percent = item[6]
            # text_content += f'''<tr><td align="center"><a href='{URL}{ths_code}'>{name}</a></td><td align="center">{code}</td><td align="center">{golden_cross_socre}</td><td align="center">{ma_up_combo}</td><td align="center">{golden_cross_combo}</td><td align="center">{price}</td><td align="center">&nbsp;{gains_percent}</td></tr>'''
            text_content += f"""<tr><td align="center"><a href='{URL}{ths_code}'>{name}</a></td><td align="center">{code}</td><td align="center">{ma_up_combo}</td><td align="center">{golden_cross_combo}</td><td align="center">{price}</td><td align="center">&nbsp;{gains_percent}</td></tr>"""

        text_content += "</table>"
        text_content += """</div>"""
    else:
        if title == "":
            text_content += f"""<div align=center>无</div>"""
        else:
            text_content += f"""<div align=center><b>{title}</b></br>无</div>"""
        text_content += "<br/>"
    text_content += "<br/>" * 1

    # # 说明信息
    # if data.__len__() > 0:
    #     text_content += """</p>"""
    #     text_content += """<b>筛选条件：</b>""" + "<br/>"
    #     condition_list2 = list(condition_list2)
    #     condition_list2 = sorted(condition_list2)
    #     start_i = 0
    #     for i in range(len(condition_list2)):
    #         text_content += f"""{start_i + i + 1}、{condition_list2[i]}""" + "<br/>"
    #     text_content += """<p>"""
    #     # text_content += "<br/>"

    # 说明信息
    # text_content += '''</p>'''
    # text_content += '''<b>参数说明：</b>''' + "<br/>"
    # text_content += '''1、K线类型：日K''' + "<br/>"
    # text_content += '''2、计算金叉均线：MA3，MA15''' + "<br/>"
    # text_content += '''3、布林线参数：mid=15，std=2''' + "<br/>"
    # text_content += '''<p>'''

    # text_content += "<br/>" * 3

    ## 数据表格2
    # text_content += '<div style="text-align:center">'
    # text_content += f"<a href='{URL}{ths_code13}'>日经</a>"
    # text_content += f"：{emoji13}" + "&nbsp;" * 2 + f"{emoji1313}"
    # text_content += "　" * 1
    # text_content += f"<a href='{URL}{ths_code14}'>多伦多</a>"
    # text_content += f"：{emoji14}" + "&nbsp;" * 2 + f"{emoji1414}"
    # text_content += "</div>"
    # text_content += "<br/>"

    # table_head_common = f'''
    # <table border="0" align="center"><tr><td align="center" bgcolor="#AFD7F5" width="300">&nbsp;&nbsp;&nbsp;名称&nbsp;&nbsp;&nbsp;</td><td align="center" bgcolor="#AFD7F5" width="80">Code</td><td align="center" bgcolor="#AFD7F5" width="80">GxSc</td><td align="center" bgcolor="#AFD7F5" width="80">MaC</td><td align="center" bgcolor="#AFD7F5" width="80">GxC</td><td align="center" bgcolor="#AFD7F5" width="80">价格</td><td align="center" bgcolor="#AFD7F5" width="100">涨幅</td></tr>
    # '''
    table_head_common = f"""
    <table border="0" align="center"><tr><td align="center" bgcolor="#AFD7F5" width="280">&nbsp;&nbsp;&nbsp;名称&nbsp;&nbsp;&nbsp;</td><td align="center" bgcolor="#AFD7F5" width="80">Code</td><td align="center" bgcolor="#AFD7F5" width="80">Sco↓</td><td align="center" bgcolor="#AFD7F5" width="80">MaC</td><td align="center" bgcolor="#AFD7F5" width="80">GxC</td><td align="center" bgcolor="#AFD7F5" width="80">价格</td><td align="center" bgcolor="#AFD7F5" width="100">涨幅</td></tr>
    """
    data = email_info_list2
    title = "买入点排行"
    if data.__len__() > 0:
        if len(title) > 0:
            text_content += f"""<div align=center><b>{title}</b></div>"""
        text_content += """<div align=center>"""
        text_content += table_head_common
        for item in data:
            name = item[0]
            name = name.replace("ETF", "")
            if len(name) > 4:
                name = name[:4] + "."
            ths_code = item[1]
            code = ths_code[3:]
            golden_cross_socre = item[2]
            ma_up_combo = item[3]
            golden_cross_combo = item[4]
            price = round(item[5], 2)
            gains_percent = item[6]
            # text_content += f'''<tr><td align="center"><a href='{URL}{ths_code}'>{name}</a></td><td align="center">{code}</td><td align="center">{golden_cross_socre}</td><td align="center">{ma_up_combo}</td><td align="center">{golden_cross_combo}</td><td align="center">{price}</td><td align="center">&nbsp;{gains_percent}</td></tr>'''
            text_content += f"""<tr><td align="center"><a href='{URL}{ths_code}'>{name}</a></td><td align="center">{code}</td><td align="center">{golden_cross_socre}</td><td align="center">{ma_up_combo}</td><td align="center">{golden_cross_combo}</td><td align="center">{price}</td><td align="center">&nbsp;{gains_percent}</td></tr>"""

        text_content += "</table>"
        text_content += """</div>"""
    else:
        if title == "":
            text_content += f"""<div align=center>无</div>"""
        else:
            text_content += f"""<div align=center><b>{title}</b></br>无</div>"""
        text_content += "<br/>"

    # # 说明信息
    # if data.__len__() > 0:
    #     text_content += """</p>"""
    #     text_content += """<b>筛选条件：</b>""" + "<br/>"
    #     condition_list = list(condition_list)
    #     condition_list = sorted(condition_list)
    #     start_i = 0
    #     for i in range(len(condition_list)):
    #         text_content += f"""{start_i + i + 1}、{condition_list[i]}""" + "<br/>"
    #     text_content += """<p>"""

    # 说明信息
    # text_content += '''</p>'''
    # text_content += '''<b>参数说明：</b>''' + "<br/>"
    # text_content += '''1、K线类型：日K''' + "<br/>"
    # text_content += '''2、计算金叉均线：MA3，MA15''' + "<br/>"
    # text_content += '''3、布林线参数：mid=15，std=2''' + "<br/>"
    # text_content += '''<p>'''

    text_content += "<br/>" * 3

    ## 截图表格1
    data = email_info_list
    title = ""
    table_head_common = f"""<table border="0">"""
    if data.__len__() > 0:
        if len(title) > 0:
            text_content += f"""<div align=center><b>{title}</b></div>"""
        text_content += """<div align=center>"""
        text_content += table_head_common
        for item in data:
            name = item[0]
            ths_code = item[1]
            code = ths_code[3:]
            # text_content += f'''<tr><td align="center"><font size="6">{code}</font></td><td align="center"><font size="6">&nbsp;&nbsp;</font></a></td><td align="center"><a href='{URL}{ths_code}'><font size="6">{name}</font></a></td></tr>'''
            text_content += (
                f"""<tr><td align="center"><font size="6">{code}</font></td></tr>"""
            )

            # text_content += f'''<tr><td align="center"><a href='{URL}{ths_code}'><font size="5">{name}</font></a></td><td align="center"><font size="5">&nbsp;&nbsp;{code}</font></td></tr>'''
        text_content += "</table>"
        text_content += """</div>"""
    else:
        if title == "":
            text_content += f"""<div align=center>无</div>"""
        else:
            text_content += f"""<div align=center><b>{title}</b></br>无</div>"""
    text_content += "<br/>"

    text_content += "<br/>" * 3
    text_content += "<br/>" * 3

    ## 截图表格2
    data = email_info_list2
    title = ""
    table_head_common = f"""<table border="0">"""
    if data.__len__() > 0:
        if len(title) > 0:
            text_content += f"""<div align=center>{title}</div>"""
        text_content += """<div align=center>"""
        text_content += table_head_common
        for item in data:
            name = item[0]
            ths_code = item[1]
            code = ths_code[3:]
            # text_content += f'''<tr><td align="center"><font size="6">{code}</font></td><td align="center"><font size="6">&nbsp;&nbsp;</font></a></td><td align="center"><a href='{URL}{ths_code}'><font size="6">{name}</font></a></td></tr>'''
            text_content += (
                f"""<tr><td align="center"><font size="6">{code}</font></td></tr>"""
            )

            # text_content += f'''<tr><td align="center"><a href='{URL}{ths_code}'><font size="5">{name}</font></a></td><td align="center"><font size="5">&nbsp;&nbsp;{code}</font></td></tr>'''
        text_content += "</table>"
        text_content += """</div>"""
    else:
        if title == "":
            text_content += f"""<div align=center>无</div>"""
        else:
            text_content += f"""<div align=center><b>{title}</b></br>无</div>"""
    text_content += "<br/>"

    text_content += "<br/>" * 35
    week_list = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
    week_day = week_list[datetime.datetime.now().weekday()]
    subject = f"ETF排行｜{emoji1}{emoji1x}｜{emoji2}{emoji2x}｜{emoji3}{emoji3x}｜{get_timestamp_human()[:16]} {week_day}"
    text = text_content

    send_email_remind(subject, text)


if __name__ == "__main__":
    main()
